package controllers

import (
	"golanger.com/utils"
	"jk/jklog"
	"net/http"
)

type PageInvitation struct {
	Application
}

type RequestPerson struct {
	Id     string
	Name   string
	Passwd string
	Type   int
}

type RequestPersons struct {
	Persons []RequestPerson
}

func initRequestPerson(id string, name string, passwd string) RequestPerson {
	return RequestPerson{
		Id:     id,
		Name:   name,
		Passwd: passwd,
	}
}

/*
www.kina.so/invitation/invitation.html?id=mzb&pd=mzb123
www.kina.so/invitation/invitation.html?id=zm&pd=zm678
www.kina.so/invitation/invitation.html?id=tw&pd=twtw
www.kina.so/invitation/invitation.html?id=wjb&pd=wjb135
www.kina.so/invitation/invitation.html?id=zc&pd=zzcc
www.kina.so/invitation/invitation.html?id=lgq&pd=llgq
www.kina.so/invitation/invitation.html?id=zy&pd=yz
www.kina.so/invitation/invitation.html?id=zwq&pd=12zwq
www.kina.so/invitation/invitation.html?id=hjl&pd=hhjjll
www.kina.so/invitation/invitation.html?id=wj&pd=wz
www.kina.so/invitation/invitation.html?id=wtz&pd=ztw

www.kina.so/invitation/invitation.html?id=dsf&pd=21dsf
www.kina.so/invitation/invitation.html?id=hcf&pd=ffcchh
www.kina.so/invitation/invitation.html?id=hcq&pd=ccqqhh
www.kina.so/invitation/invitation.html?id=zm&pd=89zm
www.kina.so/invitation/invitation.html?id=hyw&pd=wyhyw
*/

func initRequestPersons() RequestPersons {
	var rps RequestPersons
	rp := initRequestPerson("huangzong", "黄总及您的家人", "hz")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("hsz", "黄总及您的家人", "hhsz")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("wl", "王工和家人", "wwll")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("cmz", "陈经理及家人", "cjl")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("bxq", "卞新全携佳人", "qxb")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("fq", "方祺", "qqff")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("yr", "姚瑞", "12yr")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("wsf", "汪师傅", "wwq")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("fhj", "方厚继携佳人", "jjhf")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("dw", "杜伟携佳人", "wd12")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("wfy", "王丰勇", "yfw45")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("cyy", "曹迎迎及您相公", "cyy89")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("mdm", "马东梅及您相公", "mdm123")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("tdr", "汤道荣", "rdt456")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("jdy", "江姐", "dyj")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)

	rp = initRequestPerson("jw", "姜维", "dy")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("zh", "郑浩及您的家人", "zh678")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("wg", "刚哥及您的家人", "wwgg")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("ll", "刘博及您的家人", "lb")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("hjs", "何继胜携佳人", "hjs19")
	rp.Type = 1
	rps.Persons = append(rps.Persons, rp)

	/* 同学 */
	rp = initRequestPerson("zzz", "小赵携佳人", "zzz")
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("mzb", "马总及夫人", "mzb123")
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("zm", "张敏及夫人", "zm678")
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("tw", "陶威及夫人", "twtw")
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("wjb", "汪继佰", "wjb135")
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("zc", "邹董", "zzcc")
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("lgq", "刘总", "llgq")
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("zy", "张跃", "yz")
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("zwq", "赵万晴", "12zwq")
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("hjl", "黄金龙", "hhjjll")
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("wj", "吴总及夫人", "wz")
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("wtz", "王廷柱", "ztw")
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("zc", "张超", "111zc")
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("sl", "苏刘", "sl432")
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("zxf", "张旭峰携佳人", "ffxxzz")
	rps.Persons = append(rps.Persons, rp)

	rp = initRequestPerson("dsf", "丁士凤", "21dsf")
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("hcf", "胡翠芬", "ffcchh")
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("hcq", "洪超群", "ccqqhh")
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("zm", "赵敏", "89zm")
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("hyw", "何忆雯", "wyhyw")
	rps.Persons = append(rps.Persons, rp)
	rp = initRequestPerson("hyy", "何玉叶", "hyy159")
	rps.Persons = append(rps.Persons, rp)

	return rps
}

func init() {
	App.RegisterController("invitation/", PageInvitation{})
}

func (p *PageInvitation) Invitation(rw http.ResponseWriter, req *http.Request) {
	p.Document.Title = p.LANG["invitation"]

	// first init all person
	rps := initRequestPersons()

	var rp RequestPerson

	// get id to check
	var ret = 0
	if req.Method == "GET" {
		id := p.GET["id"]
		passwd := p.GET["pd"]
		jklog.L().Infoln("Welcome ", id, " request ")

		for _, k := range rps.Persons {
			if k.Id == id && k.Passwd == passwd {
				rp = k
				p.Document.Title += "-" + "欢迎" + k.Name
				ret = 1
				break
			}
		}
	}

	if ret == 0 {
		rp.Name = "您"
	}

	body := utils.M{}
	body["rp"] = rp
	p.Body = body
}
